package com.aki.ai_property.service.impl;

import com.aki.ai_property.dao.SellHouseDao;
import com.aki.ai_property.entity.House;
import com.aki.ai_property.entity.SellHouse;
import com.aki.ai_property.service.intf.HouseService;
import com.aki.ai_property.service.intf.SellHouseService;
import com.aki.ai_property.util.StringUtil;
import com.aki.ai_property.vo.PageBean;
import com.aki.ai_property.vo.Result;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * Author:WuChuangChuang
 * Date:2022/8/30 18:45
 */
@Service
public class SellHouseServiceImpl implements SellHouseService {
    @Autowired
    private SellHouseDao dao;

    /** 新增 */
    @Override
    public Result save(SellHouse sellHouse) {
        if (dao.save(sellHouse) >0){
            return Result.ok("新增成功");
        }
        return Result.fail("新增失败");
    }

    /** 修改 */
    @Override
    public Result update(SellHouse sellHouse) {
        if (dao.update(sellHouse) >0){
            return Result.ok("修改成功");
        }
        return Result.fail("修改失败");
    }

    /** 删除 */
    @Override
    public Result delete(int id) {
        if (dao.delete(id) >0){
            return Result.ok("删除成功");
        }
        return Result.fail("删除失败");
    }


    /** 查询条数 */
    @Override
    public PageBean selectPage(String houseType,int page,int limit) {
        if (StringUtil.isNotEmpty(houseType)){
            houseType="%"+houseType+"%";
        }
        int start = (page-1)*limit;
        return PageBean.ok(dao.selectCount(houseType), dao.selectPage(houseType,page, limit));
    }
}
